$(function () {
  // 匹配邮箱 汉字
  const [reg, regHz] = [
    /^\w+@[a-zA-Z0-9]{2,10}(?:\.[a-z]{2,4}){1,3}$/,
    /^[\u4e00-\u9fa5]{0,}$/,
  ];

  //   注册
  $(".dl").click(function () {
    if (reg.test($("#inp_email").val())) {
      getAjax();
    } else {
      topInfo("注册失败", "请输入正确的邮箱格式");
    }
  });

  function getAjax() {
    $.ajax({
      type: "GET",
      url: "http://192.168.43.8:8081/register",
      data: {
        name: $("#inp_name").val(),
        account: $("#inp_email").val(),
        possword: $("#inp_pwd").val(),
      },
      success: function (res) {
        if (res.status == 1) {
          topInfo(res.msg, "3秒后跳转登录页");
          setTimeout(function () {
            window.location.href = "./login.html";
          }, 2500);
        } else {
          topInfo(res.msg, "注册失败");
        }
      },
    });
  }
  function topInfo(message, title) {
    iziToast.show({
      class: "test",
      color: "dark",
      icon: "icon-contacts",
      title: title,
      message: message,
      position: "topCenter",
      transitionIn: "flipInX",
      transitionOut: "flipOutX",
      progressBarColor: "rgb(0, 255, 184)",
      image: "img/avatar.jpg",
      imageWidth: 70,
      timeout: 2500,
      layout: 2,
      onClose: function () {
          console.log("ok");
      },
      iconColor: "rgb(0, 255, 184)",
    });
  }
});
